home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / STRINGS.SWG / 0017_WILDCRD2.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  2KB  |  66 lines

  1. {
  2. > Does anyone know how to pass a wildcard Filename to a parameter String and
  3. > have the code grab the actual full Filename?
  4.  
  5. not quite, but close.  Consider the Function Wild below.  if you should do a
  6. findfirst/findnext and run the Function wild on each found name you get what
  7. you want.
  8. }
  9.  
  10. Function Wild(FileName, Card : String) : Boolean;
  11. {Returns True if the wildcard description in 'card' matches 'flname'
  12. according to Dos wildcard principles.  The 'card' String MUST have a period!
  13. Example: Wild('test.tat','t*.t?t' returns True}
  14. Var
  15.  c        : Char;
  16.  p,i,n,l  : Byte;
  17.  
  18. begin
  19.   Wild := True;
  20.   {test For special Case first}
  21.   if Card = '*.*' then
  22.     Exit;
  23.   Wild := False;
  24.   p := Pos('.', Card);
  25.   i := Pos('.', FileName);
  26.   if p = 0 then
  27.   begin
  28.     Writeln('Invalid use of Function "wild".  Program halted.');
  29.     Writeln('Wild card must contain a period.');
  30.     Halt;
  31.   end;
  32.   {test the situation beFore the period}
  33.   n := 1;
  34.   Repeat
  35.     c := UpCase(Card[n]);
  36.     if c = '*' then
  37.       n := p
  38.     else
  39.     if (upCase(FileName[n]) = c) or (c = '?') then
  40.       inc(n)
  41.     else
  42.       Exit;
  43.   Until n >= p;
  44.  
  45.   {Now check after the period}
  46.   n := p + 1; {one position past the period of the wild card}
  47.   l := Length(FileName);
  48.   Inc(i); {one position past the period of the Filename}
  49.   Repeat
  50.     if n > Length(Card) then
  51.       Exit;
  52.     c := UpCase(Card[n]);
  53.     if c = '*' then
  54.       i := l + 1 {in order to end the loop}
  55.     else
  56.     if (UpCase(FileName[i]) = c) or (c = '?') then
  57.     begin
  58.       Inc(n);
  59.       Inc(i);
  60.     end
  61.     else
  62.       Exit;
  63.   Until i > l;
  64.  
  65.   Wild := True;
  66. End;